package com.dragon.sdgp.util;


import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class PasswordUtil {

    public static String encode(String password){
        return new BCryptPasswordEncoder().encode(password);
    }

    public static String decrypt(String keyStr, String password){
        int key = 0;
        for (char c : keyStr.toCharArray()) {
            key ^= c;
        }
        StringBuilder correctPassword = new StringBuilder();
        for (char c : password.toCharArray()) {
            correctPassword.append((char) (c ^ key));
        }
        return correctPassword.toString();
    }

    public static boolean verify(String rawPassword, String encodePassword){
        return new BCryptPasswordEncoder().matches(rawPassword, encodePassword);
    }
}
